package KK.Hunter.Effect
{
	import KK.Tween.TweenLite;
	
	import flash.display.DisplayObjectContainer;
	import flash.filters.BlurFilter;
	
	public class BlurEffect implements IEffect
	{
		
		static public const BLUR:int=255;
		public function BlurEffect()
		{
			//TODO: implement function
		}
		
		public function Show(mc:DisplayObjectContainer, delay:Number):void
		{
			//TODO: implement function 
			var obj:Object=new Object();
			obj.x=BLUR;
//			TweenLite.to(filter,delay,{blurX:0,blurY:0,onComplete:Complete,onCompleteParams:[mc,true]});
			TweenLite.to(obj,delay,{x:0,onUpdate:Update,onUpdateParams:[mc,obj]});
			 
		}
		
		public function Hide(mc:DisplayObjectContainer, delay:Number):void
		{
			//TODO: implement function
			/*
			var filter:BlurFilter=new BlurFilter();
			filter.blurX=0;
			filter.blurY=0;
			mc.filters=[filter];
			TweenLite.to(filter,delay,{blurX:100,blurY:100,onComplete:Complete,onCompleteParams:[mc,false]});
			*/
			
			var obj:Object=new Object();
			obj.x=0;
			mc.cacheAsBitmap=true;
			TweenLite.to(obj,delay,{x:BLUR,onUpdate:Update,onUpdateParams:[mc,obj]});
			
		}
		private function Update(mc:DisplayObjectContainer,obj:Object):void{ 
			var filter:Object;
			for each(filter in mc.filters){
				if(filter is BlurFilter)
				{
					break;
				}
			}
			if(!filter)
			{
				filter=new BlurFilter();
			}
			filter.blurX=obj.x;
			filter.blurY=obj.x;
			mc.filters=[filter];
		}
		private function Complete(mc:DisplayObjectContainer,bool:Boolean):void{
			mc.visible=bool;
			mc.cacheAsBitmap=false;
		}
	}
}